
export default {
    /**
     * 网络请求
     * @param {JQuery} client jquery对象
     * @param {String} url 请求地址
     * @param {String} type 请求类型，GET,POST
     * @param {JSONObject} data 数据
     * @param {Function} successCallback 成功回调函数
     * @param {Function} failCallback 失败回调函数
     * @param {Function} completeCallback 完成回调函数
     */
    request:function(client,url,type,data,successCallback,failCallback,completeCallback){
        var $ = client;
        var token = sessionStorage.getItem("token");
        var t = (new Date()).getTime();
        if(data == null){
            if(type.toUpperCase() == "GET"){
                data = { _t:t};
            }
        }
        if(type.toUpperCase() == "POST"){
            url = url + "?_t" + t;
            data = JSON.stringify(data);
        } else {
            data._t = t;
        }
        $.ajax({
            url:url,
            type:type,
            data:data,
            headers:{"x-access-token":token},
            dataType:'json',
            contentType:'application/json;chartset=UTF-8',
            success:function(rspData,status,xhr){
              if(successCallback){
                successCallback(rspData,status,xhr);
              }
            },
            fail:function(){
                if(failCallback){
                    failCallback();
                }
            },
            complete:function(xhr){
                if(completeCallback){
                    completeCallback(xhr);
                }
            }
          });
    }
}